﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Shapes;

namespace bgp8.Controls
{
    public sealed partial class Token : GamePiece
    {
        public Token() 
        {
            this.InitializeComponent();
            this.Width = 80;
            this.Height = 80;
            this.Fill = new SolidColorBrush(Colors.Turquoise);
            this.Stroke = new SolidColorBrush(Colors.White);
            SizeChanged += Token_SizeChanged;
            buildTriangle();
        }

        public Token(Token cpy) 
        {
            this.InitializeComponent();
            this.Width = cpy.Width;
            this.Height = cpy.Height;
            this.Fill = cpy.Fill;
            this.Stroke = cpy.Stroke;
            SizeChanged += Token_SizeChanged;
            buildTriangle();
        }

        public override GamePiece Clone() 
        {
            return new Token(this);
        }


        void Token_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            buildTriangle();
        }

        private void buildTriangle() 
        {
            PointCollection newTrianglePoints = new PointCollection();
            Point p1 = new Point(this.Width / 2.0, 0);
            Point p2 = new Point(this.Width / 3.0, this.Height / 3.0);
            Point p3 = new Point(this.Width * 2.0 / 3.0, this.Height / 3.0);
            trianglePoints = newTrianglePoints;
        }

        public Brush Stroke
        {
            get { return (Brush)GetValue(StrokeProperty); }
            set { SetValue(StrokeProperty, value); }
        }
        public Brush Fill 
        {
            get { return (Brush)GetValue(FillProperty); }
            set { SetValue(FillProperty, value); }
        }

        public PointCollection trianglePoints
        {
            get { return (PointCollection)GetValue(TrianglePointsProperty); }
            set { SetValue(TrianglePointsProperty, value); }
        }


        public static DependencyProperty TrianglePointsProperty = DependencyProperty.Register("TrianglePoints", typeof(PointCollection), typeof(Token), null);
        public static DependencyProperty FillProperty = DependencyProperty.Register("Fill", typeof(Brush), typeof(Token), null);
        public static DependencyProperty StrokeProperty = DependencyProperty.Register("Stroke", typeof(Brush), typeof(Token), null);

    }
}
